package t10086;

import allrobots.sendMessages.Register.Registration;
import t10086.Data.Map.TextCoordinate;
import t10086.Data.Robot.RobotType;
import t10086.Model.Messages.Message;
import t10086.Model.Messages.MessageType;

import java.io.*;
import java.net.*;

public class ClientTest {
    public static void main(String[] args) {
        String host = "localhost"; // 服务器的 IP 地址
        int port = 4400;          // 服务器的端口

        try (Socket socket = new Socket(host, port)) {
            // 获取服务器的输入流
            ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream());
            ObjectInputStream in = new ObjectInputStream(socket.getInputStream());
            out.writeObject(new Message(MessageType.REGISTER,
                    new Registration(RobotType.ROBOT,"111",new InetSocketAddress("0.0.0.0",233),new TextCoordinate(2,3))));
            out.flush();
           while (true) {
               Object res = in.readObject();
               if (res instanceof Message) {
                   Message msg = (Message) res;
                   System.out.println((Long) msg.getData());
               }else {
                   continue;
               }

           }


            // 关闭连接

        } catch (IOException | ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
